package cn.yangliu.comm.config;

import cn.yangliu.comm.CommConst;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * 作者 杨柳
 * 创建时间 2017-08-29 11:08
 */
@Configuration
public class AsyncConfig {
    @Bean
    public Executor executor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(CommConst.EXECUTOR_CORE_POOL_SIZE);
        executor.setMaxPoolSize(CommConst.EXECUTOR_MAX_POOL_SIZE);
        executor.setQueueCapacity(CommConst.EXECUTOR_QUEUE_CAPACITY);
        executor.setThreadNamePrefix("custom-executor");
        executor.initialize();
        return executor;
    }
}
